/**
*      author: Y_Yao
*      created: 2025-01-25 13:42:39
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int X[N],P[N];
int sum[N];
int n,q;

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> X[i];
    }
    for(int i = 1;i <= n;i++)
    {
        cin >> P[i];
        sum[i] = sum[i-1] + P[i];
    }
    cin >> q;
    while(q--)
    {
        int l,r;
        cin >> l >> r;
        auto it1 = lower_bound(X + 1,X + n + 1,l) - X;
        auto it2 = upper_bound(X + 1,X + n + 1,r) - X - 1;
        cout << sum[it2] - sum[it1-1] << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}